﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using CoreData;
using SchoolManagementSystem.Controls;
namespace SchoolManagementSystem.Forms.BusinessForm
{
    public partial class frmStockBegin : DevExpress.XtraEditors.XtraForm
    {
        public frmStockBegin()
        {
            InitializeComponent();

            lookUpEdit_Room.Properties.DataSource = RegisterService.RegisterServices.ProductWareHouseService.GetListByParent(" where ParentID = 0");
            lookUpEdit_Room.Properties.ValueMember = "ID";
            lookUpEdit_Room.Properties.DisplayMember = "Name";
            lookUpEdit_Room.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Name", "Phòng"));
            lookUpEdit_Room.EditValue = "1";

            barButtonItem_Delete.Visibility =DevExpress.XtraBars.BarItemVisibility.Never;

            //var settingV = RegisterService.RegisterServices.SettingService.GetValueByName("BEGINSTOCK");
            //if (settingV.SettingValue == "0")
            //    btnBeginStock.Enabled = true;
            //else
            //    btnBeginStock.Enabled = false;
        }

        private void barButtonItem_AddNew_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmStockBegin_Detail frm = new frmStockBegin_Detail();
            frm.ShowDialog();
        }
        void LoadBeginStock()
        {
            var dataDetail = RegisterService.RegisterServices.BeginStockService.GetList();
            gridControl1.DataSource = dataDetail;
            
            gridView1.RefreshData();
            SetDescriptionForColumn.SetDescription(gridView1, new BeginStock());
        }

        private void cmdFillter_Click(object sender, EventArgs e)
        {
           
        }

        private void lookUpEdit_Room_EditValueChanged(object sender, EventArgs e)
        {
            LoadBeginStock();
        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
           
                var data = (IList<Product_Warehouse>)RegisterService.RegisterServices.ProductWareHouseService.GetList("  Code = 'Main'");
                if (data.Count <= 0)
                {
                    long _ProductID = (long)gridView1.GetRowCellValue(e.RowHandle, "ProductID");
                    IList<Inventory_Detail> dataDetail = new List<Inventory_Detail>();
                    dataDetail = RegisterService.RegisterServices.Inventory_DetailService.GetList_InventoryDetail((long)lookUpEdit_Room.EditValue, _ProductID);
                    gridControl2.DataSource = dataDetail;
                    gridView1.RefreshData();
                }
                else
                {
                    IList<Inventory_Detail> dataDetail = new List<Inventory_Detail>();
                    dataDetail = RegisterService.RegisterServices.Inventory_DetailService.GetList_ProductBeginStock("where 1=1");
                    gridControl2.DataSource = dataDetail;
                    gridView1.RefreshData();
                }
        }

        private void btnBeginStock_Click(object sender, EventArgs e)
        {
            frmStockBegin_Detail frm = new frmStockBegin_Detail();
            frm.ShowDialog();
        }
    }
}